package com.ymatou.iapi.trading.userquery.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.userquery.parameter.resp.BuyerOrderInfo;
import com.ymatou.iapi.trading.userquery.parameter.resp.GetBuyerOrderListResp;
import com.ymatou.iapi.trading.userquery.service.GetBuyerOrderListCall;
import com.ymatou.iapi.trading.userquery.service.GetBuyerOrderListCall_net;
import com.ymatou.query.trading.api.parameter.GetBuyerOrderListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;

/**
 * 根据订单状态查询相关订单信息列表（带分页） FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetBuyerOrderList {

	private static GetBuyerOrderListBean getbuyerorderlistbean;
	private static GetBuyerOrderListCall getbuyerorderlistcall;
	private static GetBuyerOrderListCall_net getBuyerOrderListCall_net;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据订单状态查询相关订单信息列表（带分页）");
	}

	@Before
	public void caseUp() {
		getbuyerorderlistbean = new GetBuyerOrderListBean();
		getbuyerorderlistcall = new GetBuyerOrderListCall();
		getBuyerOrderListCall_net=new GetBuyerOrderListCall_net();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbuyerorderlistcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify(){
		
		GetBuyerOrderListResp expectResponse = getBuyerOrderListCall_net.getBuyerGroupOrderInfosResp();
		GetBuyerOrderListResp actualResponse = getbuyerorderlistcall.getBuyerGroupOrderInfosResp();
		 
		List<BuyerOrderInfo> expectOrders=expectResponse.getOrderInfoList();
		List<BuyerOrderInfo> actualOrders=actualResponse.getOrderInfoList();
		
		
		actualOrders.sort(( a,b)->{			
			if (a.getOrderId()>	b.getOrderId())
				return -1;
			else {
				return 1;
				}
        	});

		for (int i=0;i<expectOrders.size();i++){
			BuyerOrderInfo expect=expectOrders.get(i);
			BuyerOrderInfo actual=actualOrders.get(i);
			
			DataUtil.verify(expect.getOrderId(), actual.getOrderId(),"验证 BuyerOrderInfo.orderId");
			DataUtil.verify(expect.getTradingStatus(), actual.getTradingStatus(),"验证 BuyerOrderInfo.tradingStatus");
			DataUtil.verify(expect.getAddTime(), actual.getAddTime(),"验证 BuyerOrderInfo.addTime");
			DataUtil.verify(expect.getBillCodeList().size()==0?null:expect.getBillCodeList(), actual.getBillCodeList(),"验证 BuyerOrderInfo.billCodeList");
			
	
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_001() {
		Logger.start(true,"根据订单状态查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			getbuyerorderlistbean.setBuyerId(userId);
			// 当前页码数
			int CurrentPageNum = 1;
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(1);
			getbuyerorderlistbean.setOrderStatusList(orderStatus);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(5);
			
			getBuyerOrderListCall_net.setData(getbuyerorderlistbean);
			getBuyerOrderListCall_net.callService();
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");
			
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_002() {
		Logger.start(true,"根据订单状态查询查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			getbuyerorderlistbean.setBuyerId(userId);
			// 当前页码数
			int CurrentPageNum = 1;
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(4);
			getbuyerorderlistbean.setOrderStatusList(orderStatus);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(30);
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();
			getBuyerOrderListCall_net.setData(getbuyerorderlistbean);
			getBuyerOrderListCall_net.callService();

			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");
			
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_003() {
		Logger.start(true,"根据订单状态查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			getbuyerorderlistbean.setBuyerId(userId);
			// 当前页码数
			int CurrentPageNum = 1;
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(1);
			orderStatus.add(2);
			orderStatus.add(3);
			orderStatus.add(4);
			orderStatus.add(12);
			orderStatus.add(13);
			orderStatus.add(16);
			orderStatus.add(17);
			orderStatus.add(18);
			getbuyerorderlistbean.setOrderStatusList(orderStatus);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(20);
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();
			getBuyerOrderListCall_net.setData(getbuyerorderlistbean);
			getBuyerOrderListCall_net.callService();

			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");
			
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_004() {
		Logger.start(true,"根据订单状态查询成功,当前不为第一页");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			getbuyerorderlistbean.setBuyerId(userId);
			// 当前页码数
			int CurrentPageNum =1;
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> orderStatus = new ArrayList<Integer>();
			//orderStatus.add(1);
			orderStatus.add(2);
			orderStatus.add(3);
			orderStatus.add(4);
			orderStatus.add(12);
			orderStatus.add(13);
			orderStatus.add(16);
			orderStatus.add(17);
			orderStatus.add(18);
			getbuyerorderlistbean.setOrderStatusList(orderStatus);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(20);
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();
			getBuyerOrderListCall_net.setData(getbuyerorderlistbean);
			getBuyerOrderListCall_net.callService();

			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");
			
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}